package com.xzzz.backend.bsms.server.base.yuque;

import com.xzzz.backend.bsms.loadbalancer.CustomCpuWeightLBConfig;
import com.xzzz.backend.bsms.server.base.yuque.config.YuqueFeignFallbackFactory;
import com.xzzz.backend.bsms.server.base.yuque.config.YuqueFeignConfig;
import com.xzzz.backend.bsms.server.base.yuque.pojo.UserRes;
import com.xzzz.common.base.pojo.R;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;

/**
 * FeignClient:
 * <p>value: 调用的服务名称
 * <p>fallback: 回调类
 * <p>fallbackFactory: 异常处理对象
 * <p>
 * 有两种回调处理方式:
 * <p>1. @FeignClient(value = "backend-bsms", configuration = AuthFeignConfig.class, fallback = AuthFeignServiceFallback.class)
 * 这种方式直接定义回调类
 * <p>2. @FeignClient(value = "backend-bsms", configuration = AuthFeignConfig.class, fallbackFactory = AuthFeignServiceFallbackFactory.class)
 * 这种方式通过回调工厂创建回调类
 *
 * @author xzzz
 */
@FeignClient(value = "backend-blog", contextId = "YuqueController", configuration = YuqueFeignConfig.class, fallback = YuqueFeignFallbackFactory.class)
@LoadBalancerClient(value = "backend-bsms", configuration = CustomCpuWeightLBConfig.class)
public interface YuqueFeign {

    /**
     * feign 不支持使用 {@link ModelAttribute} 注解来传递请求参数对象, 如果接口提供方给与的是对象类型的请求参数, Feign 中需要使用
     * {@link SpringQueryMap} 来映射
     *
     * @return 响应
     */
    @GetMapping("/yuque/user")
    R<UserRes> user();
}
